//
//  XHWelcomeViewController.swift
//  gu-新浪微博
//
//  Created by xiaohui on 16/6/28.
//  Copyright © 2016年 gusheghui. All rights reserved.
//

import UIKit
import SDWebImage
class XHWelcomeViewController: UIViewController {

    override func loadView() {
        view = bgImageView
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        
        self.headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
        UIView.animateWithDuration(3, delay: 2, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            //更新约束
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
            
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                     //动画完成  改变根控制器
                        
                        //01 发送通知
                       NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootVcNoti, object: "welcome")
                        
                })
                
        }
        
        
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()


        setupUI()
    }

    private func setupUI(){
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        headImageView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.top.equalTo(view).offset(400)
            make.centerX.equalTo(view)
        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
        }
        
        
    }
    
    
    private lazy var bgImageView:UIImageView = UIImageView(imgName: "ad_background")
    
    private lazy var headImageView:UIImageView = {
        let img = UIImageView(imgName: "avatar_default_big")
        img.layer.borderColor = ThemeColor.CGColor
        img.layer.cornerRadius = 45
        img.layer.borderWidth = 3
        img.layer.masksToBounds = true
      
        img.sd_setImageWithURL(NSURL(string: XHUserAccountTools.sharedTools.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named: "ad_background"))
        return img
    }()
    
    private lazy var messageLabel:UILabel = {
       let lab = UILabel()
        lab.text = "欢迎回来"
        lab.font = UIFont.systemFontOfSize(18)
        lab.textColor = UIColor.grayColor()
        lab.textAlignment = .Center
        lab.alpha = 0
        return lab
    }()
    
    

}
